﻿/*************************************************************************************
 * 文 件 名:   HK_BlankItem
 * 
 * 描    述:   填空题模板类
 * 
 * 版    本：  V1.0
 * 创 建 者：  京产肠饭
 * 创建时间：  2021/11/25
 * 链   接：  https://gitee.com/JingChanChangFan/hk_-unity-tools
*************************************************************************************/

using System.Collections.Generic;
using UnityEngine.UI;

public class HK_BlankItem : HK_QuesItem
{
    public List<InputField> input_List;
    List<string> answer_List = new List<string>();
    List<InputField> activeInput_List = new List<InputField>();

    public void InitQuesItem(HK_BlankData quesData, int id)
    {
        ID_Txt.text = id.ToString() + "、";

        answer_List = quesData.Answer_List;

        for (int i = 0; i < answer_List.Count; i++)
        {
            input_List[i].gameObject.SetActive(true);
            activeInput_List.Add(input_List[i]);
        }

        for (int i = 0; i < activeInput_List.Count; i++)
        {
            activeInput_List[i].onEndEdit.AddListener(input =>
            {
                isCorrect = true;

                for (int i = 0; i < answer_List.Count; i++)
                {
                    if (answer_List[i].Trim() != activeInput_List[i].text.Trim())
                        isCorrect = false;
                }
            });
        }

        quesName_Txt.text = quesData.QuesName;
        analysis_Txt.text = quesData.Analysis;
    }

    public void DisableInput()
    {
        for (int i = 0; i < activeInput_List.Count; i++)
        {
            activeInput_List[i].interactable = false;
        }
    }

    public override bool IsDone()
    {
        isDone = true;

        for (int i = 0; i < activeInput_List.Count; i++)
        {
            if (string.IsNullOrEmpty(activeInput_List[i].text.Trim()))
                isDone = false;
        }

        return isDone;
    }

    public override bool IsCorrect()
    {
        return isCorrect;
    }
}
